package org.come.socket;

import org.come.action.MapAction;
import org.come.bean.Account;

import io.netty.channel.ChannelHandlerContext;

public class SendMessageUntil {
	// 重新连接标识
	public static boolean CanDoConnectOrNo = true;
	// 发送信息给服务端的（登录注册信息发送通道）
	public static ChannelHandlerContext SendMesToServer;
	static String FB = "\n";

	/** zrikka 2020 0414 */
    public static String gameServerKey = "";
    public static String accServerKey = "";

    public static String project = "";
    public static Account account = null;

//  public static String loginIp = "47.104.237.87";
//  public static int loginPort = 7100;
//    public static String loginIp = "103.85.86.54";
//    public static String loginIp = "192.168.0.105";
//    public static int loginPort = 7101;
    /***/
    
	public static void toServer(final String sendmes) {
	    if (MapAction.flagAction.get(gameServerKey)) {
            MapAction.nettyAction.get(gameServerKey).writeAndFlush(sendmes + FB);
        }
//		if (CanDoConnectOrNo) {
//			SendMesToServer.writeAndFlush(sendmes + FB);
////			SendMesToServer.writeAndFlush("1*-*68941@+@hyh123@+@hyh123@+@" + FB);
////			SendMesToServer.writeAndFlush("b5,N3,aw,aF,De,41,wD,kB,h3,i0,Re,io,nZ,aF,iJ,H3,Gc,hl,aw,b5,h3,Fq,FO,i0,nZ,aF,iJ,H3,Gc,hL,aw,b5,h3,Fq,FO,i0,nZ,aF,iJ" + FB);
//			
//			
////			final Channel x=SendMesToServer.channel();
////			x.eventLoop().execute(new Runnable() {
////				@Override
////				public void run() {
////				    x.writeAndFlush(sendmes + FB);
////				}
////			});
//		}
	}
	// 与 账号服务器 的交互   
    public static void loginToServer(String sendmes) {
        if (MapAction.flagAction.get(accServerKey)) {
            MapAction.nettyAction.get(accServerKey).writeAndFlush(sendmes + FB);
        }
    }
	/** 实例化连接 */
	public static void getClientUntil() throws Exception {
		if (SendMesToServer == null) {
			// 启动服务器连接
			GameClient client = new GameClient();
			client.start();
		}
	}
	public static void getClientUntil(String ip, int port) throws Exception {
		if (SendMesToServer == null) {
			// 启动服务器连接
			GameClient client = new GameClient(ip,port);
			client.start();
		}
	}
    /** 实例化连接 */
//    public static void getClientUntil(String ip, int port, String serverType) throws Exception {
//        ChannelHandlerContext SendMesToServer = MapAction.nettyAction.get(ip + "|" + port);
//        if (SendMesToServer == null) {
//            // 启动服务器连接
//            GameClient client = new GameClient(ip, port, serverType);
//            client.start();
//            Thread.sleep(700);
//        }
//    }
    
}
